﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Text;
using Portal.Environment;
using Portal.Language;
using Portal.Interface;

namespace Portal.CMS
{
    public class AddAdvImage : Portal.Interface.WebPart
    {
        public override string WebPartId
        {
            get
            {
                return "AddAdvImage";
            }
        }

        public override string Title
        {
            get
            {
                return ResourceBLL.GetText(WebPartId,"Title","Thêm mới ảnh quảng cáo");
            }
        }

        public override string Description
        {
            get
            {
                return ResourceBLL.GetText(WebPartId,"Description","");
            }
        }

        public override string RenderWebPart(LoadParamCls loadParamCls)
        {
            AjaxPro.Utility.RegisterTypeForAjax(typeof(AddAdvImage));
            string belongSite = (string)Environments.Request("belongSite");


            Environment.Environments.CheckSessionTimeOut(true);
            PermissionTypeCls PermissionTypeCls = Environments.FindPermissionType(new AdvImage().PermissionTypes, "AdvImageWebPart");
            Environment.Permission.CheckPermission(Environment.Environments.CurrentLoginUser.LoginName, PermissionTypeCls.PermissionTypeCode, "AddAdvImage", WebPartId, null, true);

            string RetHtml =
                Portal.Environment.WebPartUtilities.AttachJavascript("Portal.CMS", "AdvImage.js") +
                "<input id=txtBelongSite type=hidden value=\"" + belongSite + "\">" +
                "<table>" +
                "       <tr>"+
                "           <td>"+ResourceBLL.GetText(WebPartId,"Subject","Tiêu đề")+":</td>"+
                "           <td><input class=cssTextBoxDialog  id=txtSubject></td>" +
                "       </tr>"+
                "       <tr>" +
                "           <td>" + ResourceBLL.GetText(WebPartId, "Description", "Mô tả") + ":</td>" +
                "           <td><textarea id=txtDescription></textarea></td>" +
                "       </tr>" +
                "       <tr>" +
                "           <td></td>" +
                "           <td><input onclick=javascript:SaveClientAddAdvImage(); type=button value=\"" + ResourceBLL.GetText(WebPartId, "saveButton", "Ghi lại") + "\"><input type=button onclick=javascript:window.close(); value=\"" + ResourceBLL.GetText(WebPartId, "CloseButton", "Thoát") + "\"></td>" +
                "       </tr>" +
                "</table>";
            RetHtml = Environments.GetFormDialog(RetHtml, ResourceBLL.GetText(WebPartId,"Title","Thêm bộ ảnh"));
            return RetHtml;
        }



        [AjaxPro.AjaxMethod]
        public string ServerSideAddAdvImage(string belongSite,string AdvImageName,string Description)
        {
            try
            {
                Environment.Environments.CheckSessionTimeOut(true);
                if (AdvImageName.Trim().Length == 0) throw new Exception(ResourceBLL.GetText(WebPartId,"EnterName","Nhập tiêu đề!"));
                new AdvImageBLL().AddAdvImage(null, Environments.ActiveLanguage, AdvImageName, Description, belongSite);
                return ResourceBLL.GetText(WebPartId,"MessageAddOk","Tạo mới thành công!");
            }
            catch (Exception ex)
            {
                return "ERROR: " + ex.Message.ToString();
            }
        }


        [AjaxPro.AjaxMethod]
        public string ProcessHtml(string Html,int Index)
        {
            Html=Html.Replace("<div class=\"cssDivRowItem\" id=\"divRowItem_"+Index+"\"></div>","");
            return Html;
        }
    }
}